package org.x.user.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.x.common.base.result.Result;
import org.x.user.entity.SysLogsDO;
import org.x.user.dto.PageResult;
import org.x.user.query.QueryGroup;
import org.x.user.query.SysLogsQuery;
import org.x.user.service.LogsService;

/**
 * 审计日志管理
 *
 * @author 夏包包
 * @date 2025-03-08 13:39:03
 */
@Tag(name = "审计日志管理")
@RequestMapping("logs")
@RestController
public class LogsController {

    @Autowired
    private LogsService logsService;

    /**
     * 查询所有日志
     *
     * @return
     */
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @Operation(summary = "查询所有日志")
    public Result<PageResult<SysLogsDO>> allLogs() {
        PageResult<SysLogsDO> result = logsService.allLogs();
        return Result.success(result);
    }

    /**
     * 根据日志ID查询日志
     *
     * @param logQuery 审计日志查询对象
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @Operation(summary = "根据日志ID查询日志")
    public Result<SysLogsDO> logInfo(@Validated(QueryGroup.class) SysLogsQuery logQuery) {
        SysLogsDO result = logsService.logInfo(logQuery);
        return Result.success(result);
    }

    /**
     * 根据租户ID查询日志
     *
     * @param logQuery 审计日志查询对象
     * @return
     */
    @RequestMapping(value = "/byTenant", method = RequestMethod.GET)
    @Operation(summary = "根据租户ID查询日志")
    public Result<PageResult<SysLogsDO>> logsByTenant(@Validated(QueryGroup.class) SysLogsQuery logQuery) {
        PageResult<SysLogsDO> result = logsService.logsByTenant(logQuery);
        return Result.success(result);
    }

    /**
     * 根据操作用户ID查询日志
     *
     * @param logQuery 审计日志查询对象
     * @return
     */
    @RequestMapping(value = "/byUser", method = RequestMethod.GET)
    @Operation(summary = "根据操作用户ID查询日志")
    public Result<PageResult<SysLogsDO>> logsByUser(@Validated(QueryGroup.class) SysLogsQuery logQuery) {
        PageResult<SysLogsDO> result = logsService.logsByUser(logQuery);
        return Result.success(result);
    }

    /**
     * 根据日志级别查询日志
     *
     * @param logQuery 审计日志查询对象
     * @return
     */
    @RequestMapping(value = "/byLevel", method = RequestMethod.GET)
    @Operation(summary = "根据日志级别查询日志")
    public Result<PageResult<SysLogsDO>> logsByLevel(@Validated(QueryGroup.class) SysLogsQuery logQuery) {
        PageResult<SysLogsDO> result = logsService.logsByLevel(logQuery);
        return Result.success(result);
    }

    /**
     * 根据时间范围查询日志
     *
     * @param logQuery 审计日志查询对象
     * @return
     */
    @RequestMapping(value = "/byTimeRange", method = RequestMethod.GET)
    @Operation(summary = "根据时间范围查询日志")
    public Result<PageResult<SysLogsDO>> logsByTimeRange(@Validated(QueryGroup.class) SysLogsQuery logQuery) {
        PageResult<SysLogsDO> result = logsService.logsByTimeRange(logQuery);
        return Result.success(result);
    }
}
